package com.bluegalaxy.nhb.snapi;

import com.bluegalaxy.nhb.snapi.core.common.OvervivwUtil;
import com.bluegalaxy.nhb.snservice.common.utils.DateUtil;
import com.bluegalaxy.nhb.snservice.license.License;
import com.bluegalaxy.nhb.snservice.license.LicenseEntity;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Date;

@SpringBootApplication(scanBasePackages = {"com.bluegalaxy.nhb"})
@EnableCaching
@EnableTransactionManagement
@tk.mybatis.spring.annotation.MapperScan(basePackages = "com.bluegalaxy.nhb.snservice.dao")
public class CkApiApplication {

    public static void main(String[] args) {

        InputStream inputStream = CkApiApplication.class.getClassLoader().getResourceAsStream("license.txt");
        License license = new License();
        LicenseEntity licenseData = license.loadLicense(inputStream, Base64.getDecoder().decode("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCoKSiJdKndyvd3yU1Ua+YzidF6Aq6CJqME2q477Rl2uMndXt6+head15SqcoXVg877Unfka+h0hQrItF2ziSBXY6m5zNTC5DRVK5+mkZTqq2EHUMX2RiNHILn6EAlU+Y3kysWXkpC3DPznnLXNtwtgivKPenG8PB1QwfRzXOMIKQIDAQAB"));
//        System.out.println(new String(licenseData.getData()));
//        System.out.println(licenseData.getExpireTime());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//要转换的时间格式
        Date date;
        try {
            date = sdf.parse(sdf.format(licenseData.getExpireTime()));
            System.out.println(new String(licenseData.getData()) +" 有效期至："+ DateUtil.parseDateStr(DateUtil.DATE_yyyy_MM_dd_HH_mm_ss,date));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        OvervivwUtil.put("expire_time_key",licenseData.getExpireTime());
//        CacheUtils.put("xiaoxiangCache","expire_time_key",licenseData.getExpireTime(),null,null);
        SpringApplication.run(CkApiApplication.class, args);
    }

}
